package resources;

import java.io.InputStream;
import java.util.List;

import parser.ParseException;
import parser.Parser;
import parser.ParserConstants;
import parser.ParserTokenManager;
import parser.SimpleCharStream;
import parser.TokenMgrError;
import src.Main;

public class Compilador {

	public Parser parser;
	ParserTokenManager manager;

	public Compilador(InputStream stream) {
		parser = new Parser(stream);
		manager = new ParserTokenManager(new SimpleCharStream(stream));
	}

	public void compilar() {
		do {
			try {
				parser.start();
				Main.window.getTxtrConsole().append("Token:\t" + parser.token.image + " \t Linha: " + parser.token.beginLine + " \t Coluna: " + parser.token.beginColumn + " \t Categoria: " + ParserConstants.tokenImage[parser.token.kind] + " \t Tipo: " + parser.token.kind + "\n");
				System.out.println(parser.token.image + " -- " + ParserConstants.tokenImage[parser.token.kind]);
			} catch (ParseException e) {
				parser.getNextToken();
				System.out.println("parser Exception:" + parser.token.image + " -- " + ParserConstants.tokenImage[parser.token.kind]);
			} catch (TokenMgrError e) {
				e.printStackTrace();
			}
		} while (parser.token.kind != ParserConstants.EOF);
	}
}